/*
 * Copyright 2012 Marcin Blazejewski
 *
 * This file is part of Ground0.
 *
 * Ground0 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Ground0 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Ground0. If not, see <http://www.gnu.org/licenses/>.
 *
 */


#ifndef COLLISION_SPHERES_H_
#define COLLISION_SPHERES_H_

#include "collision.hpp"
#include "geometry.hpp"
#include "midlev.hpp"
#include "quat.hpp"

#include <list>
#include <vector>
#include <fstream>


class Stuff;
class CollisionSphere;
class CollisionQuad;

#define CN_SPHERE            0
#define CN_QUAD              1

class CollisionNode {
public:
    int node_type;
    virtual void load(std::istream &s) = 0;
    virtual void save(std::ostream &s) = 0;
};

class CollisionSphere : public CollisionNode {
public:
    Vector center;
    float radius;

    CollisionSphere() { node_type = CN_SPHERE; }
    virtual void load(std::istream &s);
    virtual void save(std::ostream &s);
};

class CollisionQuad : public CollisionNode {
public:
    Vector v[4];

    CollisionQuad() { node_type = CN_QUAD; }
    virtual void load(std::istream &s) {}
    virtual void save(std::ostream &s) {}
};


class CollisionModel {
public:
    static const char id[];
    static const unsigned char version;
    list<CollisionNode*> nodes;

    CollisionModel();
    ~CollisionModel();
    void load(std::istream &s);
    void save(std::ostream &s);
    
    void invalidate() { }
    bool test(Stuff &s1, Stuff &s2, Vector *n, Vector *p1, Vector *p2);
};


#endif
